package com.bjsxt.userscenter.head.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bjsxt.userscenter.common.controller.BaseController;
import com.bjsxt.userscenter.common.util.ConstatFinalUtil;
import com.bjsxt.userscenter.outer.service.IOuterService;

/**
 * 所有外部的接口
 * 
 * @author gyq
 *
 */
@Controller
@RequestMapping("/outer/")
public class OuterController extends BaseController
{
	@Resource
	private IOuterService outerService;

	/**
	 * 地区列表
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/regionList",produces = "text/html;charset=UTF-8")
	public String regionList(HttpServletRequest request)
	{
		ConstatFinalUtil.LOGGER.info("---regionList---");
		long st = System.currentTimeMillis() ; 
		JSONObject resultJSON = new JSONObject();
		String json = request.getParameter("json");
		if (json == null)
		{
			json = "";
		}
		
		JSONObject reqJSON = null ;
		try
		{
			/* 将上行的json字符串,变成json */
			reqJSON = (JSONObject) JSON.parse(json);
		} catch (Exception e)
		{
			resultJSON.put("code", "11");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("11"));
		}
		
		try
		{
			/* 如果是第一个版本,调用第一个方法 */
			if ("1".equalsIgnoreCase(reqJSON.getString("version")))
			{
				resultJSON = this.outerService.regionList01Service(reqJSON);
			}else
			{
				resultJSON.put("version", reqJSON.getString("version"));
				resultJSON.put("code", "9");
				resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("9"));
			}
		} catch (Exception e)
		{
			ConstatFinalUtil.LOGGER.error("拼装JSON对象出错了;上行数据:{}",reqJSON,e);
			resultJSON.put("code", "-1");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("-1") + e.toString());
		}
		long ed = System.currentTimeMillis() ; 
		resultJSON.put("consume", (ed-st) + "毫秒");
		return resultJSON + "";
	}
}
